package com.ruoyi.college.service.impl;

import java.util.List;

import com.ruoyi.college.domain.Course;
import com.ruoyi.college.domain.Semester;
import com.ruoyi.college.domain.Teacher;
import com.ruoyi.college.service.ICourseService;
import com.ruoyi.college.service.ISemesterService;
import com.ruoyi.college.service.ITeacherService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.college.mapper.CourseArrangementMapper;
import com.ruoyi.college.domain.CourseArrangement;
import com.ruoyi.college.service.ICourseArrangementService;
import com.ruoyi.common.core.text.Convert;

/**
 * 课程安排主Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-25
 */
@Service
public class CourseArrangementServiceImpl implements ICourseArrangementService 
{
    @Autowired
    private CourseArrangementMapper courseArrangementMapper;


    @Autowired
    private ITeacherService  teacherService;

    @Autowired
    private ICourseService courseService;

    @Autowired
    private ISemesterService semesterService;

    /**
     * 查询课程安排主
     * 
     * @param arrangementId 课程安排主主键
     * @return 课程安排主
     */
    @Override
    public CourseArrangement selectCourseArrangementByArrangementId(Long arrangementId)
    {
        return courseArrangementMapper.selectCourseArrangementByArrangementId(arrangementId);
    }

    /**
     * 查询课程安排主列表
     * 
     * @param courseArrangement 课程安排主
     * @return 课程安排主
     */
    @Override
    public List<CourseArrangement> selectCourseArrangementList(CourseArrangement courseArrangement)
    {
        List<CourseArrangement> courseArrangements = courseArrangementMapper.selectCourseArrangementList(courseArrangement);
        courseArrangements.forEach(item->{
            Long leaderId = item.getLeaderId();
            Teacher teacher = teacherService.selectTeacherByTeacherId(leaderId);
            item.setLeaderName(teacher.getTeacherName());
            Long courseId = item.getCourseId();
            Course course = courseService.selectCourseByCourseId(courseId);
            item.setCourseName(course.getCourseName());
            Semester semester = semesterService.selectSemesterBySemesterId(item.getSemesterId());
            item.setSemesterName(semester.getSemesterName());
        });
        return courseArrangements;
    }

    /**
     * 新增课程安排主
     * 
     * @param courseArrangement 课程安排主
     * @return 结果
     */
    @Override
    public int insertCourseArrangement(CourseArrangement courseArrangement)
    {
        courseArrangement.setCreateTime(DateUtils.getNowDate());
        return courseArrangementMapper.insertCourseArrangement(courseArrangement);
    }

    /**
     * 修改课程安排主
     * 
     * @param courseArrangement 课程安排主
     * @return 结果
     */
    @Override
    public int updateCourseArrangement(CourseArrangement courseArrangement)
    {
        courseArrangement.setUpdateTime(DateUtils.getNowDate());
        return courseArrangementMapper.updateCourseArrangement(courseArrangement);
    }

    /**
     * 批量删除课程安排主
     * 
     * @param arrangementIds 需要删除的课程安排主主键
     * @return 结果
     */
    @Override
    public int deleteCourseArrangementByArrangementIds(String arrangementIds)
    {
        return courseArrangementMapper.deleteCourseArrangementByArrangementIds(Convert.toStrArray(arrangementIds));
    }

    /**
     * 删除课程安排主信息
     * 
     * @param arrangementId 课程安排主主键
     * @return 结果
     */
    @Override
    public int deleteCourseArrangementByArrangementId(Long arrangementId)
    {
        return courseArrangementMapper.deleteCourseArrangementByArrangementId(arrangementId);
    }
}
